var express = require('express');
var router = express.Router();

/* GET users listing. */
router.post('/', function(req, res, next) {
	console.log(req.body);
	var name = req.body.name,
	  	idNum = req.body.idNum,
	  	phone = req.body.phone,
	  	wantId = req.body.wantId,
	  	orderNum = req.body.orderNum,
	  	note = req.body.note;

	var mysql = require('mysql');
	var connection = mysql.createConnection({
	    host: '106.14.254.124',          //主机 
	    user: 'wangruiyu',               //MySQL认证用户名 
	    password: 'Wangruiyu1990',       //MySQL认证用户密码 
	    database: 'wangruiyu', 
	    port: '3306'                     //端口号 
	});
	connection.connect();
	var param = [name,idNum,phone,wantId,orderNum,note]; 
	var sql = "insert into user (name,idNum,phone,wantId,orderNum,note) values(?,?,?,?,?,?)";
	connection.query(sql,param, function(err, results) {
	  if (err) throw err;
	  res.redirect('http://www.wangry.com:3001');
	});
	connection.end();
});

module.exports = router;
